﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SqlClient;
using System.Data;
using System.Collections;

using XJX.DataLayer;

namespace XJX.BusinessLayer
{
    public class SysMessage
    {
        private string ConnToData;

        public SysMessage(string newConnectionString)
        {
            ConnToData = newConnectionString;
        }

        //得到某位家庭的所有信件信息
        public Hashtable Get_One_Family_Message_From_UID(string UID, int PageIndex, int PageSize)
        {
            Hashtable ht = new Hashtable();
            DataTable dt = new DataTable();
            int PageCount = 0;
            int TotalCount = 0;

            DataSet ds = new XJX.DataLayer.SysMessage(ConnToData).Get_One_Family_Message_From_UID(UID, "Family_Message", PageIndex, PageSize, out PageCount, out TotalCount);
            dt = ds.Tables[0];

            ArrayList data = Common.DataTable2ArrayList(dt);

            ht["PageCount"] = PageCount;//页数,将在哈希表中输出成字符串。
            ht["RecordCount"] = TotalCount;//记录总数
            ht["rows"] = data;

            return ht;
        }

        //得到某位家庭的未读信件数量
        public DataTable Get_One_Family_Message_From_UID(string UID)
        {
            DataTable dt = new DataTable();
            int PageCount = 0;
            int TotalCount = 0;

            int PageIndex = 1;
            int PageSize = 1000;

            DataSet ds = new XJX.DataLayer.SysMessage(ConnToData).Get_One_Family_Message_From_UID(UID, "Family_Message", PageIndex, PageSize, out PageCount, out TotalCount);
            dt = ds.Tables[0];

            return dt;
        }

        //删除一条家庭信件
        public bool Del_One_Family_Message_From_ID(string ID)
        {
            bool b;

            try
            {
                b = new XJX.DataLayer.SysMessage(ConnToData).Del_One_Family_Message_From_ID(ID);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return b;
        }
        //添加站内信息
        public bool Add_New_SysMsg
        (
            string uid,
            string bid,
            string title,
            string msg,
            out string ReturnFieldValue   //返回字段值
        )
        {
            bool b;

            try
            {
                b = new XJX.DataLayer.SysMessage(ConnToData).Add_New_SysMsg(uid,bid,title,msg,out ReturnFieldValue);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return b;
        }

        //添加未成功发送的短信消息
        public bool Add_New_NoSuccessShortMsg
        (
            string SysMsgID,
            string TemplateID,
            string ClientIP
        )
        {
            bool b;

            try
            {
                b = new XJX.DataLayer.SysMessage(ConnToData).Add_New_NoSuccessShortMsg(SysMsgID, TemplateID, ClientIP);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return b;
        }


        //标记一条信息为已读
        public bool Mark_One_SysMsg_Readed(string ID)
        {
            bool b;

            try
            {
                b = new XJX.DataLayer.SysMessage(ConnToData).Mark_One_SysMsg_Readed(ID);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return b;
        }
    }
}
